﻿using System.Collections.Generic;

namespace MDAControlsFramework.Helpers {
	/// <summary>
	/// Uchová společné nastavení
	/// </summary>
	public class MDAProperty: IMDAObject {
		Dictionary<string, string> _properties = new Dictionary<string, string>(10);
		List<IMDAObject> _objects = new List<IMDAObject>(10);
		private string _name = "null";

		public object Clone() {
			MDAProperty clone = this.MemberwiseClone() as MDAProperty;
			return clone;
		}

		public string GetName() {
			return _name;
		}

		public bool AddObject(IMDAObject objectInstance) {
			_objects.Add(objectInstance);
			return true;
		}

		public bool SetProperty(string name, string value) {
			if (name == "name") {
				_name = value;
				return true;
			}
			_properties.Add(name, value);
			return true;
		}

		public void AddEvent(string eventName, string eventHandler) {
			return;
		}

		/// <summary>
		/// nastaví uložené hodnoty danému objektu
		/// </summary>
		/// <param name="mainObject">objekt, kterému jsou hodnoty nastavovány</param>
		public void SetPropertyTo(IMDAObject mainObject) {
			for (int i = 0; i < _objects.Count; i++) {
				mainObject.AddObject(_objects[i]);
			}

			foreach (string propertyName in _properties.Keys) {
				mainObject.SetProperty(propertyName, _properties[propertyName]);
			}
		}
	}
}
